package planit.controller.impl;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;

import planit.model.Model;
import planit.view.EditGroupDialog;

@SuppressWarnings("serial")
public class EditGroupController extends AbstractAction {
	private Model model;

	public EditGroupController(Model model) {
		this.model = model;
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		EditGroupDialog dialog = (EditGroupDialog)this.getValue("EditGroupDialog");

		if (dialog.getGroupName().length() > 0) {
			model.getSchedule().getGroup(dialog.getGroupId())
			.setDescription(dialog.getGroupDescription());
			model.getSchedule().getGroup(dialog.getGroupId())
			.setName(dialog.getGroupName());
		} else {
			JOptionPane.showMessageDialog(null,
					"You have to enter the name of the group", "Error",
					JOptionPane.WARNING_MESSAGE);
		}
	}

}
